#ifndef PORTABLE_BYTECODE_ARRAY_H_
#define PORTABLE_BYTECODE_ARRAY_H_

#include <stdint.h>

#include "src/pbc/portable-bytecode-register.h"
#include "src/pbc/portable-constant-array-builder.h"

namespace portable {

class BytecodeArray final {
 public:
  BytecodeArray(int length, const std::vector<uint8_t>& raw_bytecodes,
                int register_count, uint16_t parameter_count,
                int exception_count, ConstantPool* constant_pool);
  ~BytecodeArray();

  // Note: the parameter count includes the implicit 'this' receiver.
  uint16_t parameter_count() const;
  uint16_t parameter_count_without_receiver() const;

  int exception_count() const;

  int register_count() const;
  int length() const;
  ConstantPool* constant_pool();
  uintptr_t GetFirstBytecodeAddress();

  static void Disassemble(BytecodeArray* source, std::ostream& os);

  void set_incoming_new_target_or_generator_register(Register val);
  Register incoming_new_target_or_generator_register() const;

  const ConstantPool* constant_pool() const { return constant_pool_; }
  const std::vector<uint8_t>& raw_bytecodes_data() const {
    return raw_bytecodes_data_;
  }

 private:
  uint16_t parameter_count_;
  int register_count_;
  int exception_count_;
  int bytecodes_size_;
  Register incoming_new_target_or_generator_register_;
  const std::vector<uint8_t> raw_bytecodes_data_;
  ConstantPool* constant_pool_;
};

}  // namespace portable

#endif  // PORTABLE_BYTECODE_ARRAY_H_
